/**
 * the Requestobserver object is the callback class that monitors all httprequests 
 * sent, through the observe function. It creates a httpChannel and instaniates new
 * request objects from it.
 */
function RequestObserver ()
{
        this.observe = function(subject, topic, data) 
        {
           try {
 
                if (sp.fuzzer.isFuzzing == true){ //we are in fuzzing state ignore http requests for now! (the Xmlhttp requests are hadled in the fuzzer)
                     //alert ("RequestObserver> fuzz: " + sp.fuzzer.isFuzzing);
                    return;
                }
                else
                {
                    var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
                    var dummyHeaderInfo = new HeaderInfo();
                    var req = new Request(httpChannel);
                    
                    for (i in sp.settings.ignored){ //we should ignore boring requests like images or other stuff specified by user
                        if (req.Url.indexOf(sp.settings.ignored[i]) > 0){
                            req.log = false;
                            break; 
                        }
                    }
    
                    if (topic == "http-on-examine-response"){   
                        httpChannel.visitResponseHeaders(dummyHeaderInfo);
                        req.responseHeaders = dummyHeaderInfo.Headers;      
                    }
               
                    if (topic == "http-on-modify-request") {
                        httpChannel.visitRequestHeaders(dummyHeaderInfo);
                        req.requestHeaders = dummyHeaderInfo.Headers;    
                    }
                    
                    if (sp.settings.logRequests == true && req.log == true && req.ResponseStatus > 0)  //we only log requests that are not ignored! (Even if logging is enabled).
                    { 
                        logHandler("sent: " + req.toString() + "status: " + req.ResponseStatus );
                    }
                    
                    if (req.log == true && req.Url.indexOf("=") > 0 && req.ResponseStatus > 0 )
                    {
                        
                        sp.attackVectors[req.Url]=req;
                        req.id = sp.attackVectors.length;
                                
                        if (sp.settings.keepToSite == true )
                        {
                            var loc =  content.document.location.toString();
                            var baseUrl = loc.split('/');
                            var base = (baseUrl[2]);
                                
                            if (req.Url.indexOf(base) > 0)
                            {
                                logHandler(req.Url +" Seems to be a attackvector");
                                sp.addToRequestTree(req);    
                            }
                            else
                            {
                                 logHandler(req.Url +" Seems to be a attackvector but on external url");
                                 sp.addToExternalTree(req);    
                            }
                                                        //   if   here we hsould put code that compares the base url with the browser base url
                        }
                        else
                        { 
                            //alert (content.document.location);
                            logHandler(req.Url +" Seems to be a attackvector");
                            sp.addToRequestTree(req);
                        }
                    }
                    
                }                
            }catch (e){errorHandler(e);}    
        }
}

 